package com.jsmile.cloud.msgcenter.zf.handler;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.egzosn.pay.common.api.PayMessageHandler;
import com.egzosn.pay.common.api.PayService;
import com.egzosn.pay.common.bean.PayOutMessage;
import com.egzosn.pay.common.exception.PayErrorException;
import com.egzosn.pay.wx.bean.WxPayMessage;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class WxPayMessageHandler implements PayMessageHandler<WxPayMessage, PayService> {

    @Override
    public PayOutMessage handle(WxPayMessage wxPayMessage, Map<String, Object> map, PayService payService) throws PayErrorException {
        log.info("微信回调：{}", JSON.toJSONString(map));
        // 交易状态
        if ("SUCCESS".equals(wxPayMessage.getPayMessage().get("result_code"))) {
            ///// 这里进行成功的处理
            return payService.getPayOutMessage("SUCCESS", "OK");
        }
        return payService.getPayOutMessage("FAIL", "失败");
    }
}
